package com.yyfax.pay.third.model.to.fuiou;

import java.io.StringWriter;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.StaxWriter;
import com.yyfax.framework.model.Content;
import com.yyfax.pay.common.annotation.FuiouSign;

/**
 * 商户协议验证码获取接口返回结果封装类
 * 
 * @author heizq
 * @date 2017-05-09 09:49:12
 * @since v1.2.0
 */
@SuppressWarnings("serial")
@XStreamAlias("RESPONSE")
@FuiouSign(signField = { "type", "version", "responsecode", "mchntcd", "mchntorderid", "userid", "orderid", "amt" })
public class ProtocolPlaceOrderFuiouContent extends Content {

	/**
	 * 版本号
	 */
	@XStreamAlias("VERSION")
	private String version = "";

	/**
	 * 类型
	 */
	@XStreamAlias("TYPE")
	private String type = "";

	/**
	 * 响应代码
	 */
	@XStreamAlias("RESPONSECODE")
	private String responsecode = "";

	/**
	 * 响应中文描述
	 */
	@XStreamAlias("RESPONSEMSG")
	private String responsemsg = "";

	/**
	 * 商户代码
	 */
	@XStreamAlias("MCHNTCD")
	private String mchntcd = "";

	/**
	 * 商户订单号
	 */
	@XStreamAlias("MCHNTORDERID")
	private String mchntorderid = "";

	/**
	 * 用户编号
	 */
	@XStreamAlias("USERID")
	private String userid = "";

	/**
	 * 富友订单号
	 */
	@XStreamAlias("ORDERID")
	private String orderid = "";

	/**
	 * 交易金额
	 */
	@XStreamAlias("AMT")
	private String amt = "";

	/**
	 * 保留字段1
	 */
	@XStreamAlias("REM1")
	private String rem1 = "";

	/**
	 * 保留字段2
	 */
	@XStreamAlias("REM2")
	private String rem2 = "";

	/**
	 * 保留字段3
	 */
	@XStreamAlias("REM3")
	private String rem3 = "";

	/**
	 * 签名类型
	 */
	@XStreamAlias("SIGNTP")
	private String signtp = "";

	/**
	 * 摘要数据
	 */
	@XStreamAlias("SIGN")
	private String sign = "";

	/**
	 * 令牌支付接口所需字段 (调支付接口时原样传送该字段)
	 */
	@XStreamAlias("SIGNPAY")
	private String signpay = "";

	/**
	 * 请求响应报文
	 */
	private String rspContent = "";

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getResponsecode() {
		return responsecode;
	}

	public void setResponsecode(String responsecode) {
		this.responsecode = responsecode;
	}

	public String getResponsemsg() {
		return responsemsg;
	}

	public void setResponsemsg(String responsemsg) {
		this.responsemsg = responsemsg;
	}

	public String getMchntcd() {
		return mchntcd;
	}

	public void setMchntcd(String mchntcd) {
		this.mchntcd = mchntcd;
	}

	public String getMchntorderid() {
		return mchntorderid;
	}

	public void setMchntorderid(String mchntorderid) {
		this.mchntorderid = mchntorderid;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getOrderid() {
		return orderid;
	}

	public void setOrderid(String orderid) {
		this.orderid = orderid;
	}

	public String getAmt() {
		return amt;
	}

	public void setAmt(String amt) {
		this.amt = amt;
	}

	public String getRem1() {
		return rem1;
	}

	public void setRem1(String rem1) {
		this.rem1 = rem1;
	}

	public String getRem2() {
		return rem2;
	}

	public void setRem2(String rem2) {
		this.rem2 = rem2;
	}

	public String getRem3() {
		return rem3;
	}

	public void setRem3(String rem3) {
		this.rem3 = rem3;
	}

	public String getSigntp() {
		return signtp;
	}

	public void setSigntp(String signtp) {
		this.signtp = signtp;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getSignpay() {
		return signpay;
	}

	public void setSignpay(String signpay) {
		this.signpay = signpay;
	}

	public String getRspContent() {
		return rspContent;
	}

	public void setRspContent(String rspContent) {
		this.rspContent = rspContent;
	}

	/**
	 * 该实体转换成XML字符串
	 * 
	 * @author heizq
	 * @date 2017-4-12 10:52:52
	 * @since v1.0.0
	 * @return 返回XML字符串
	 * @throws Exception
	 */
	public String toXml() {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("RESPONSE", ProtocolPlaceOrderFuiouContent.class);
		// return xstream.toXML(this);
		//
		try {
			StringWriter strWriter = new StringWriter();
			// don't do startDocument and do repair namespaces
			StaxWriter sw = new StaxWriter(staxDriver.getQnameMap(), staxDriver.getOutputFactory().createXMLStreamWriter(strWriter), false, true);
			xstream.marshal(this, sw);
			sw.close();
			return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + strWriter.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * XML字符串转换成实体{@link ProtocolPlaceOrderFuiouContent}
	 * 
	 * @author heizq
	 * @date 2017-4-12 10:53:28
	 * @since v1.0.0
	 * @param xml
	 * @return 返回{@link ProtocolPlaceOrderFuiouContent}
	 */
	public static ProtocolPlaceOrderFuiouContent fromXml(String xml) {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultNamespace("http://www.99bill.com/mas_cnp_merchant_interface");
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("RESPONSE", ProtocolPlaceOrderFuiouContent.class);
		return (ProtocolPlaceOrderFuiouContent) xstream.fromXML(xml);
	}

	public static void main(String[] args) throws Exception {
		System.out.println(new ProtocolPlaceOrderFuiouContent().toXml());
	}
}
